#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    int n,m,l,v;
    for(int i=0;i<t;i++){
        cin>>n>>m>>l>>v;
        int car[n][3];
        int ce[m];
        int num=0;
        for(int j=0;j<n;j++){
            cin>>car[i][0]>>car[i][1]>>car[i][2];
            if(car[i][1]>v){
                num++;
            }
        }
        for(int j=0;j<m;j++){
            cin>>ce[i];
        }
        cout<<num<<' '<<m-1<<"\n";
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
